package com.dongdongshop.consumer;

import com.dongdongshop.service.ItemPageService;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@RocketMQMessageListener(consumerGroup = "dongdongshop",messageModel = MessageModel.CLUSTERING,topic = "item-topic")
public class RocketmqConsumer implements RocketMQListener<Long[]> {

    @Autowired
    private ItemPageService itemPageService;

    @Override
    public void onMessage(Long [] ids) {
        try {
            for (Long id : ids) {
                itemPageService.createPage(id);
            }
            System.out.println("消费成功");
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("消费失败");
        }
    }
}
